#include "usrlist.h"

//usrList申请空间
usrList* mkList()
{
    usrList *list=(usrList*)malloc(sizeof(usrList));
    if(NULL == list)
    {
        printf("error...\n");
        tuichu;
    }
    else
    {
        memset(list,0,sizeof(usrList));
    }
    return list;
}

//给结构体usrNode申请空间
usrNode* mkNode()
{
    usrNode *node = (usrNode*)malloc(sizeof(usrNode));
    if(NULL == node)
    {
        printf("error...\n");
        tuichu;
    }
    else
    {
        memset(node,0,sizeof(usrNode));
    }
    return node;
}

//头插法生成链表
void myInsert(usrList *list,usrNode *node)
{
    if(NULL == list || NULL == node)
    {
        return;
    }
    node->pnext = list->pFirstNode;
    list->pFirstNode = node;
    list->LLen++;
}

//匹配
usrNode *findNodeByName(const usrList* list,const char *name)
{
    usrNode *node = NULL;
    if(NULL != list && NULL != name)
    {
        node=list->pFirstNode;
        while(NULL != node)
        {
            if(strcmp(name,node->usrName) == 0)
            {
                return node;
            }
            node = node->pnext;
        }
    }
    return node;
}

//删除用户信息节点
usrList * delUsrInfo(usrNode *node,usrList *list)
{
    usrNode *pre=list->pFirstNode;
    usrNode *cur=pre->pnext;
    while(cur != NULL)
    {
        if(strcmp(node->usrName,pre->usrName) == 0)
        {
            list->pFirstNode = pre->pnext;
            return list;
        }
        else if(strcmp(node->usrName,cur->usrName)==0)
        {
            pre->pnext=cur->pnext;
            return list;
        }
        pre=pre->pnext;
        cur=cur->pnext;
    }
    return list;
}

//用户信息链表释放
void releaseUsrList(usrNode *node,usrList *list)
{
    usrNode *p=list->pFirstNode;
    usrNode *q=p->pnext;
    while(p != NULL)
    {
        if(p != node)
        {
            free(p);
        }
        p=q;
        if(q !=NULL)
        {
            q=q->pnext;
        }
    }
    free(list);
}

//彩票信息链表释放
void releaseLyList(lyNode *node,lyList *list)
{
    lyNode *p=list->pFirstNode;
    lyNode *q=p->pnext;
    while(p != NULL)
    {
        if(p != node)
        {
            free(p);
        }
        p=q;
        if(q !=NULL)
        {
            q=q->pnext;
        }
    }
    free(list);
}

//购买彩票信息链表释放
void releaseBuyLyList(buyLyNode *node,buyLyList *list)
{
    buyLyNode *p=list->pFirstNode;
    buyLyNode *q=p->pnext;
    while(p != NULL)
    {
        if(p != node)
        {
            free(p);
        }
        p=q;
        if(q !=NULL)
        {
            q=q->pnext;
        }
    }
    free(list);
}